package com.shelpe.services.lexicon.simba;

import java.util.Date;
import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.lexicon.simba.CategoryClient.CategoryClientFallback;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

@FeignClient(name="${feign.simba.name}", url="${feign.simba.url}", fallback=CategoryClientFallback.class)
public interface CategoryClient {
	@RequestMapping(path = "/simba/taobao.simba.insight.catsinfo.get", method = RequestMethod.GET)
	CategoryListRespone findCategory(@RequestParam("category_id_list") String[] words, @RequestParam("type")int type, 
			@RequestHeader("tenantID") long tenantID);
	
	@Getter
	@Setter
	public static class CategoryListRespone extends SimbaProxyBaseDto{		
		@JsonProperty("simba_insight_catsinfo_get_response")
		private CategoryListRes res;
	}
	
	@Getter
	@Setter
	public static class CategoryListRes{		
		@JsonProperty("category_info_list")
		private CategoryList dataList;
	}
	
	@Data
	public class CategoryList {
		@JsonProperty("insight_category_info_d_t_o")
		private List<CategoryDto> categories;
	}
	
	@Data
	public static class CategoryDto{
		@JsonProperty("cat_id")
		private long categoryID;
		@JsonProperty("cat_name")
		private String name;
		@JsonProperty("cat_level")
		private int level;
		@JsonProperty("parent_cat_id")
		private long parentID;
		@JsonProperty("cat_path_id")
		private String categoryIDs;
		@JsonProperty("cat_path_name")
		private String names;
		@JsonProperty("last_sync_time")
		@JsonFormat(shape=Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
		private Date wordsUpdated;
	}
	

	@Service
	public static class CategoryClientFallback implements CategoryClient{

		@Override
		public CategoryListRespone findCategory(String[] words, int type, long tenantID) {
			return null;
		}
		
	}
}
